<?php
namespace Backstage\Controller;

use Think\Controller;

/**
 * Class LoginController
 * @author edvard
 * @time 2014.9.23 7:26
 */
class LoginController extends Controller
{

    /**
     * 跳转到登录页面
     */
    public function index()
    {
        $this->display();
    }

    /**
     * 登录业务，如果登录成功，便在页面上进行跳转
     */
    public function doLogin()
    {	
        $username = $_POST['username'];
        $password = $_POST['password'];
        if(!empty($username) && !empty($password)){
            $loginService = D('Login', 'Service');
            //登录服务
            $result = $loginService->verify($username, $password,NULL);
            //写入日志服务
            $loginService->loginLog();

            if( session(C('TYPE')) == "DISTRIBUTOR")
            {
                $result['is_distributor']=1;
            }
            else{
                $result['is_distributor']=0;
            }

            //判断是否登录，如果登录后。检测是否是手机
			if(session(C('LOGINNAME'))){
                if (isMobile()) {
				    $result['ismobile']=1;
                }
			}
            $this->ajaxReturn($result);
        }else{
            $result['content'] = "用户名/密码不能为空";
            $result['ismobile']=0;
            $this->ajaxReturn($result);
        }
    }

    /**
     * 退出登录
     * @modify qax 2014.10.15 10:26
     */
    public function exitLogin()
    {
        $loginService = D('Login', 'Service');
        $result = $loginService->exitLogin();
        $this->success($result['data']['success'], U('Login/index'));
    }

}
